package com.bazaaroid.server.gae.business.facade.impl;

import java.util.List;

import javax.ws.rs.core.MultivaluedMap;

import com.bazaaroid.server.gae.business.facade.SearchFacade;
import com.bazaaroid.server.gae.business.facade.util.SearchQueryUtil;
import com.bazaaroid.server.gae.core.dao.partner.ProductDAO;
import com.bazaaroid.server.gae.core.dto.partner.ProductSearchResultsDTO;
import com.bazaaroid.server.gae.core.ioc.GuiceFactory;
import com.bazaaroid.server.gae.core.persistence.model.partner.Product;

public class SearchFacadeImpl implements SearchFacade {

	@Override
	public ProductSearchResultsDTO searchProducts(String searchQuery) {
		String[] searchParams = SearchQueryUtil.parseQuery(searchQuery);
		ProductDAO productDAO = GuiceFactory.getInjector().getInstance(ProductDAO.class);
		List<Product> products = productDAO.getProductsBySearchParams(searchParams);
		return new ProductSearchResultsDTO(products);
	}

	@Override
	public ProductSearchResultsDTO searchProducts(
			MultivaluedMap<String, String> queryParams) {
		ProductDAO productDAO = GuiceFactory.getInjector().getInstance(ProductDAO.class);
		List<Product> products = productDAO.getProductsByQueryParams(queryParams);
		return new ProductSearchResultsDTO(products);
	}

}
